﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="send_emailgroup.aspx.cs" Inherits="system_send_emailgroup" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>群组发送邮件</title>
    <style type="text/css">
        body{
            font-size:10pt;
        }
    </style>
	<script type="text/javascript" src="../jquery/126/jquery-1.2.6.js"></script>    <script language=javascript src="../js/Function.js"></script>
    <script language=javascript src="../js/myCheck.js"></script>
    <script type="text/javascript">
        //获取编辑器中HTML内容
        function getEditorHTMLContents(EditorName) { 
            var oEditor = FCKeditorAPI.GetInstance(EditorName); 
            return(oEditor.GetXHTML(true)); 
        }

        // 获取编辑器中文字内容
        function getEditorTextContents(EditorName) { 
            var oEditor = FCKeditorAPI.GetInstance(EditorName); 
            return(oEditor.EditorDocument.body.innerText); 
        }

        // 设置编辑器中内容
        function SetEditorContents(EditorName, ContentStr) { 
            var oEditor = FCKeditorAPI.GetInstance(EditorName); 
            oEditor.SetHTML(ContentStr) ; 
        }

        function email_chk()
        {
			if(CheckText2(form1.mailtitle,"邮件标题",50)==false) return false;
			if(CheckText2(form1.sendman,"发件人",10)==false) return false;
			if(getEditorHTMLContents('fck_content')=='')
			{
				alert("内容不能空!");
				return false;
			}
			return true;
        }

        function getemails(emailtype)
        {
	        var urlstring='loademails.aspx?mailtype='+emailtype+'&_='+(new Date()).getTime();            	        $.ajax({	            url:urlstring,	            type:'get',	            dataType:'html',	            beforeSend:function()	            {	                $("#emailaddrs").empty().append("<img id='loading' src='../images/loading2.gif' />正在加载,请稍等......");	            },	            error:function()	            {	                $("#emailaddrs").empty().append("read error!");	            },	            success: function(msg)	            {	                $("#emailaddrs").empty().append(msg);	            }	        });        }
                function findemail()        {			var groups='';
			
			for(var i = 0; i < form1.elements.length; i++)
			{
				if(form1.elements[i].type=='checkbox')
				{
					if(form1.elements[i].name=='mangroup')
					{
					    if(form1.elements[i].checked)
					    {
					       var sname="'"+form1.elements[i].value+"',";
					       groups+=sname; 
					    }
					}
				}
			}
			
			var emailtype=new String(groups);
			emailtype=emailtype.substring(0,emailtype.length-1);
            getemails(emailtype);        }                function findemail2()        {			var groups='';
			
			for(var i = 0; i < form1.elements.length; i++)
			{
				if(form1.elements[i].type=='checkbox')
				{
					if(form1.elements[i].name=='mangroup2')
					{
					    if(form1.elements[i].checked)
					    {
					       var sname="'"+form1.elements[i].value+"',";
					       groups+=sname; 
					    }
					}
				}
			}
			
			var emailtype=new String(groups);
			emailtype=emailtype.substring(0,emailtype.length-1);
            //alert(emailtype);            getemails2(emailtype);        }
        function getemails2(emailtype)
        {
	        var urlstring='loademails2.aspx?mailtype='+emailtype+'&_='+(new Date()).getTime();            	        $.ajax({	            url:urlstring,	            type:'get',	            dataType:'html',	            beforeSend:function()	            {	                $("#emailaddrs").empty().append("<img id='loading' src='../images/loading2.gif' />正在加载,请稍等......");	            },	            error:function()	            {	                $("#emailaddrs").empty().append("read error!");	            },	            success: function(msg)	            {	                $("#emailaddrs").empty().append(msg);	            }	        });        }
                function gotosend(email,poster)        {	        //var mydata="userid="+$("#myuid").val()+"&poster="+poster+"&mailtitle="+escape($("#mailtitle").val())+"&sendman="+escape($("#sendman").val())+"&mailaddr="+email+"&mailcontent="+escape(getEditorHTMLContents("fck_content"))	        //window.open('sendmail.aspx?'+mydata);	        	        $.ajax({	            url:'sendmail.aspx',	            type:'post',	            data: "userid="+$("#myuid").val()+"&poster="+poster+"&mailtitle="+escape($("#mailtitle").val())+"&sendman="+escape($("#sendman").val())+"&mailaddr="+email+"&mailcontent="+escape(getEditorHTMLContents("fck_content"))	        });        }        function sendemail()        {			if(email_chk())
			{
                $("#sendmsg").empty().append("sending...!");
    			var mailnumber=1;
			    for(var i = 0; i < form1.elements.length; i++)
			    {
				    if(form1.elements[i].type=='checkbox')
				    {
					    if(form1.elements[i].name=='email')
					    {
					        if(form1.elements[i].checked)
					        {
					           var emailaddr=form1.elements[i].value;
                                if(CheckEMailStr(emailaddr))
                                {
                                    //alert(emailaddr+'('+mailnumber+')');
                                    gotosend(emailaddr,mailnumber);
                                    mailnumber++;
                                }
					        }
					    }
				    }
			    }
    	        			    //gotosend('liuys@263.net',2);
                $("#sendmsg").empty().append("send ok!");            }			
        }           	$(document).ready(function(){            $("#mailtype").load("loadmailtype.aspx");	    });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="1" cellpadding="2" cellspacing="0" style='BORDER-COLLAPSE: collapse' bordercolor="#cfdfff" width="96%" align="center">
            <tr bgcolor="#f5fafe">
                <td align="center" width="80">邮件标题</td><td align="left"><input type="text" id="mailtitle" style="width: 400px" /></td>
            </tr>
            <tr bgcolor="#f5fafe">
                <td align="center" width="80">发件人</td><td align="left"><input type="text" id="sendman" style="width: 400px" value="汽车中国 / 动感驾驭 / 汽车在线" /></td>
            </tr>
            <tr>
                <td colspan=2><FCKeditorV2:FCKeditor ID="fck_content" runat="server" BasePath="/easycrm/fckeditor/" Height="600px" Width="100%" ToolbarSet="CMS01"></FCKeditorV2:FCKeditor></td>
            </tr>
            <tr bgcolor="#f5fafe">
                <td colspan=2><input id="btncancel" type="button" value="取消" style="width: 60px;" />&nbsp;<input id="btnreset" type="button" value="重写" style="width: 60px;" />&nbsp;<input id="btnpreview" type="button" value="预览" style="width: 60px;" />&nbsp;<input id="btnsend" type="button" value="开始发送" onclick="sendemail()" style="width: 80px;" /><span id="sendmsg"></span></td>
            </tr>
        </table>
        <table border="1" cellpadding="2" cellspacing="0" style='BORDER-COLLAPSE: collapse' bordercolor="#cfdfff" width="96%" align="center">
            <tr bgcolor="#f5fafe">
                <td><div id="mailtype"></div></td>
                <td align="center"><input type="button" id="btnloadtype" value="查找" onclick="findemail()" style="width: 61px" /></td>
            </tr>
            <tr bgcolor="#f5fafe">
                <td><input id="qchb" name="mangroup2" type="checkbox" value="汽车画报" />汽车画报&nbsp;<input id="dgjy" name="mangroup2" type="checkbox" value="动感驾驭" />动感驾驭<input id="qczx" name="mangroup2" type="checkbox" value="汽车在线" />汽车在线</td>
                <td align="center"><input type="button" id="btnCompany" value="内部查找" onclick="findemail2()" style="width: 61px" /></td>
            </tr>
            <tr>
                <td colspan="2"><div id="emailaddrs"></div></td>
            </tr>
        </table>
    </div>
    <div id="myhidediv" style="VISIBILITY: hidden;"><asp:TextBox ID="myuid" runat="server"></asp:TextBox></div>
    </form>
</body>
</html>
